
/**
 * 全局变量
 */
var dIds = new Array();// 删除了的合同产品信息ID数组
var i = 0;// 数组下标
var clienteleName = "";// 客户名称


/**
 * 保存合同信息
 */
function save(){
	var json = "";
	if($("#code").val() == null || $("#code").val() == ''){
		$.jBox.tip("请输入客户合同订单号！");
		return;
	}
	if($("#clienteleCodeNum").val() == null || $("#clienteleCodeNum").val() == ''){
		$.jBox.tip("请输入写客户编号！");
		return;
	}
		$.each($("#productInfoTbody tr"), function(i,info){
			var realDetailId = $("#productInfoTbody tr:eq("+i+") input[name=realDetailId]").val();// 合同产品信息ID
			var name = $("#productInfoTbody tr:eq("+i+") input[name=name]").val();// 产品名称
			var productCode = $("#productInfoTbody tr:eq("+i+") input[name=productCode]").val();// 产品代码
			var specifications = $("#productInfoTbody tr:eq("+i+") input[name=specifications]").val();// 规格
			var brand = $("#productInfoTbody tr:eq("+i+") input[name=brand]").val();// 品牌
			var packaging = $("#productInfoTbody tr:eq("+i+") input[name=packaging]").val();// 封装
			var unit = $("#productInfoTbody tr:eq("+i+") input[name=unit]").val();// 单位
			var supplier = $("#productInfoTbody tr:eq("+i+") input[name=supplier]").val();// 供应商
			var noTaxPrice = $("#productInfoTbody tr:eq("+i+") input[name=noTaxPrice]").val();// 未税价格
			var taxPrice = $("#productInfoTbody tr:eq("+i+") input[name=taxPrice]").val();// 含税价格
			var marketPrice = $("#productInfoTbody tr:eq("+i+") input[name=marketPrice]").val();// 销售价格
			var count = $("#productInfoTbody tr:eq("+i+") input[name=count]").val();// 数量
			var brandReplace = $("#productInfoTbody tr:eq("+i+") input[name=brandReplace]").val();// 品牌替代说明
			var abnormalProblem = $("#productInfoTbody tr:eq("+i+") input[name=abnormalProblem]").val();// 异常问题确认
			var executor = $("#productInfoTbody tr:eq("+i+") input[name=executor]").val();// 对应负责人
			var enquiryDate = $("#productInfoTbody tr:eq("+i+") input[name=enquiryDate]").val();// 询价日期
			var deliveryAddress = $("#productInfoTbody tr:eq("+i+") input[name=deliveryAddress]").val();// 送货地点
			var paymentDate = $("#productInfoTbody tr:eq("+i+") input[name=paymentDate]").val();// 付款日期
			var arriveDate = $("#productInfoTbody tr:eq("+i+") input[name=arriveDate]").val();// 到货日期
			var abnormalProblem = $("#productInfoTbody tr:eq("+i+") input[name=abnormalProblem]").val();// 异常问题确认
			var deliveryDate = $("#productInfoTbody tr:eq("+i+") input[name=deliveryDatea]").val();// 送货日期
			var expirationDate = $("#productInfoTbody tr:eq("+i+") input[name=expirationDate]").val();// 保质期
			var realDetailRemarks = $("#productInfoTbody tr:eq("+i+") input[name=realDetailRemarks]").val();// 备注
			var productCodeNum = $("#productInfoTbody tr:eq("+i+") input[name=productCodeNum]").val();// 产品编号
			var supplierCodeNum = $("#productInfoTbody tr:eq("+i+") input[name=supplierCodeNum]").val();// 供应商编号
			if(typeof(realDetailId) == "undefined"){
				realDetailId = "";
			}
			if(typeof(name) == "undefined"){
				name = "";
			}
			if(typeof(productCode) == "undefined"){
				productCode = "";
			}
			if(typeof(specifications) == "undefined"){
				specifications = "";
			}
			if(typeof(brand) == "undefined"){
				brand = "";
			}
			if(typeof(packaging) == "undefined"){
				packaging = "";
			}
			if(typeof(unit) == "undefined"){
				unit = "";
			}
			if(typeof(supplier) == "undefined"){
				supplier = "";
			}
			if(typeof(noTaxPrice) == "undefined"){
				noTaxPrice = "";
			}
			if(typeof(taxPrice) == "undefined"){
				taxPrice = "";
			}
			if(typeof(marketPrice) == "undefined"){
				marketPrice = "";
			}
			if(typeof(count) == "undefined"){
				count = "";
			}
			if(typeof(brandReplace) == "undefined"){
				brandReplace = "";
			}
			if(typeof(abnormalProblem) == "undefined"){
				abnormalProblem = "";
			}
			if(typeof(executor) == "undefined"){
				executor = "";
			}
			if(typeof(deliveryAddress) == "undefined"){
				deliveryAddress = "";
			}
			if(typeof(paymentDate) == "undefined"){
				paymentDate = "";
			}
			if(typeof(arriveDate) == "undefined"){
				arriveDate = "";
			}
			if(typeof(abnormalProblem) == "undefined"){
				abnormalProblem = "";
			}
			if(typeof(deliveryDate) == "undefined"){
				deliveryDate = "";
			}
			if(typeof(expirationDate) == "undefined"){
				expirationDate = "";
			}
			if(typeof(realDetailRemarks) == "undefined"){
				realDetailRemarks = "";
			}
			if(typeof(enquiryDate) == "undefined"){
				enquiryDate = "";
			}
			if(productCodeNum == "undefined"){
				productCodeNum = "";
			}
			if(supplierCodeNum == "undefined"){
				supplierCodeNum = "";
			}
			if(i != 0){
				json = json+','
			}
			json = json+'{"realDetailId":"'+realDetailId+'","name":"'+name+'","productCode":"'+productCode+
			    '","specifications":"'+specifications+'","brand":"'+brand+'","packaging":"'+packaging+
			    '","unit":"'+unit+'","supplier":"'+supplier+'","count":"'+count+'","noTaxPrice":"'+noTaxPrice+
				'","taxPrice":"'+taxPrice+'","brandReplace":"'+brandReplace+'","abnormalProblem":"'+abnormalProblem+
				'","executor":"'+executor+'","enquiryDate":"'+enquiryDate+'","deliveryAddress":"'+deliveryAddress+
				'","paymentDate":"'+paymentDate+'","arriveDate":"'+arriveDate+'","marketPrice":"'+marketPrice+
				'","deliveryDate":"'+deliveryDate+'","expirationDate":"'+expirationDate+'","remarks":"'+realDetailRemarks+
				'","productCodeNum":"'+productCodeNum+'","supplierCodeNum":"'+supplierCodeNum+'"}';
		});
		var realDetail = '['+json+']';
		$("input[name=realDetail]").val(realDetail);
		$("input[name=ids]").val(dIds);
		$("#saveForm").submit();	// 提交表单
}

/**
 * 添加产品框
 */
function addPro(){
	$.jBox($("#divPro").html(), {
		id: 'JBoxDivPro', 
		title : "添加产品",
		width : 555,
		height : 555,
		buttons : {"选择" : false , "关闭" : true },
		submit : function(v, h, f) {
			if (v == false) {
				if(h.find("#productName").val() != "undefined"&& h.find("#productName").val() !="" ){
					var newRow = '<tr> ';
					if(typeof($("#productInfoNameSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><input type="hidden" name="realDetailId" value="" />'+
							'<span class="productInfoNameSpan">'+h.find("#productName").val()+'</span>'+
							'<input type="hidden" name="name" value="'+h.find("#productName").val()+'"/>'+
							'<input type="hidden" name="productCodeNum" value="'+h.find("#productCodeNum").val()+'"/></td>';
					}
					if(typeof($("#productCodeSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="productCodeSpan">'+h.find("#productCode").val()+'</span>'+
						'<input type="hidden" name="productCode" value="'+h.find("#productCode").val()+'"/></td>';
					}
					if(typeof($("#specificationsSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="specificationsSpan">'+h.find("#specifications").val()+'</span>'+
						'<input type="hidden" name="specifications" value="'+h.find("#specifications").val()+'"/></td>';
					}
					if(typeof($("#brandSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="brandSpan">'+h.find("#brand").val()+'</span>'+
						'<input type="hidden" name="brand" value="'+h.find("#brand").val()+'"/></td>';
					}
					if(typeof($("#packagingSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="packagingSpan">'+h.find("#packaging").val()+'</span>'+
						'<input type="hidden" name="packaging" value="'+h.find("#packaging").val()+'"/></td>';
					}
					if(typeof($("#unitNameSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="unitNameSpan">'+h.find("#unit").val()+'</span>'+
						'<input type="hidden" name="unit" value="'+h.find("#unit").val()+'"/></td>';
					}
					if(typeof($("#supplierNameSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="supplierNameSpan">'+h.find("#supplier").val()+'</span>'+
						'<input type="hidden" name="supplier" value="'+h.find("#supplier").val()+'"/>'+
						'<input type="hidden" name="supplierCodeNum" value="'+h.find("#supplierCodeNum").val()+'"/></td>';
					}
					if(typeof($("#noTaxPriceSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="noTaxPriceSpan">'+h.find("#noTaxPrice").val()+'</span>'+
						'<input type="hidden" name="noTaxPrice" value="'+h.find("#noTaxPrice").val()+'"/></td>';
					}
					if(typeof($("#taxPriceSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="taxPriceSpan">'+h.find("#taxPrice").val()+'</span>'+
						'<input type="hidden" name="taxPrice" value="'+h.find("#taxPrice").val()+'"/></td>';
					}
					if(typeof($("#marketPriceSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="marketPriceSpan">'+h.find("#marketPrice").val()+'</span>'+
						'<input type="hidden" name="marketPrice" value="'+h.find("#marketPrice").val()+'"/></td>';
					}
					if(typeof($("#countSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="countSpan">'+h.find("#count").val()+'</span>'+
						'<input type="hidden" name="count" value="'+h.find("#count").val()+'"/></td>';
					}
					if(typeof($("#brandReplaceSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="brandReplaceSpan">'+h.find("#brandReplace").val()+'</span>'+
						'<input type="hidden" name="brandReplace" value="'+h.find("#brandReplace").val()+'"/></td>';
					}
					if(typeof($("#abnormalProblemSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="abnormalProblemSpan">'+h.find("#abnormalProblem").val()+'</span>'+
						'<input type="hidden" name="abnormalProblem" value="'+h.find("#abnormalProblem").val()+'"/></td>';
					}
					if(typeof($("#executorSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="executorSpan">'+h.find("#executor").val()+'</span>'+
						'<input type="hidden" name="executor" value="'+h.find("#executor").val()+'"/></td>';
					}
					if(typeof($("#enquiryDateSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="enquiryDateSpan">'+h.find("#enquiryDate").val()+'</span>'+
						'<input type="hidden" name="enquiryDate" value="'+h.find("#enquiryDate").val()+'"/></td>';
					}
					if(typeof($("#deliveryAddressSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="deliveryAddressSpan">'+h.find("#deliveryAddress").val()+'</span>'+
						'<input type="hidden" name="deliveryAddress" value="'+h.find("#deliveryAddress").val()+'"/></td>';
					}
					if(typeof($("#deliveryDateSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="deliveryDateSpan">'+h.find("#deliveryDate").val()+'</span>'+
						'<input type="hidden" name="deliveryDatea" value="'+h.find("#deliveryDate").val()+'"/></td>';
					}
					if(typeof($("#paymentDateSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="paymentDateSpan">'+h.find("#paymentDate").val()+'</span>'+
						'<input type="hidden" name="paymentDate" value="'+h.find("#paymentDate").val()+'"/></td>';
					}
					if(typeof($("#arriveDateSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="arriveDateSpan">'+h.find("#arriveDate").val()+'</span>'+
						'<input type="hidden" name="arriveDate" value="'+h.find("#arriveDate").val()+'"/></td>';
					}
					if(typeof($("#expirationDateSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="expirationDateSpan">'+h.find("#expirationDate").val()+'</span>'+
						'<input type="hidden" name="expirationDate" value="'+h.find("#expirationDate").val()+'"/></td>';
					}
					if(typeof($("#remarksSpan").html())!="undefined"){
						newRow += '<td style="white-space: normal;"><span class="remarksSpan">'+h.find("#remarks").val()+'</span>'+
						'<input type="hidden" name="realDetailRemarks" value="'+h.find("#remarks").val()+'"/></td>';
					}
					newRow += '<td style="white-space: normal;"><a href="javascript:" onclick="ejectModifyRealDetail(this)"><i class="icon-edit"></i></a>&nbsp; '+
						'<a href="javascript:" class="deleteRow"><i class="icon-remove"></i></a></td></tr>';
					$("#productInfoTbody").append(newRow);
					$("#productName").attr("value","");
					$("#productCode").attr("value","");
					$("#specifications").attr("value","");
					$("#brand").attr("value","");
					$("#packaging").attr("value","");
					$("#unit").attr("value","");
					$("#supplier").attr("value","");
					$("#productCodeNum").attr("value","");
					$("#supplierCodeNum").attr("value","");
				}else{
					$.jBox.tip("请选择产品！", "warn");
					return false;
				}
			}else {
				$("#productName").attr("value","");
				$("#productCode").attr("value","");
				$("#specifications").attr("value","");
				$("#brand").attr("value","");
				$("#packaging").attr("value","");
				$("#unit").attr("value","");
				$("#supplier").attr("value","");
				$("#productCodeNum").attr("value","");
				$("#supplierCodeNum").attr("value","");
				return true;
			}
		}
	}); 
}

/**
 * 弹出选择信客户息框
 */
function ejectClienteleInfo(){
	$.jBox($("#choiceClienteleBox").html(), {
		id: 'jBoxClienteleInfo', 
		title : "选择客户",
		width : 'auto',
		height : 'auto',
		buttons : {"选择" : false , "关闭" : true },
		submit : function(v, h, f) {
			if (v == false) {
				if(h.find("input[name='radio']:checked").val() != null){
					var $subBox = $("input[name='radio']:checked");
					$("#clienteleCodeNum").val($subBox.parent().parent().children("td")[1].innerHTML);
    				$("#clienteleName").val($subBox.parent().parent().children("td")[2].innerHTML);
    				$("#phone").val($subBox.parent().parent().children("td")[3].innerHTML);
    				$("#fax").val($subBox.parent().parent().children("td")[4].innerHTML);
    				$("#email").val($subBox.parent().parent().children("td")[5].innerHTML);
    				$("#clienteleId").val($subBox.parent().parent().children("td")[6].innerHTML);
    				return true;
				}else{
					$.jBox.tip("请选择客户！", "warn");
					return false;
				}
			}
		}
	});
}

/**
 * 客户信息
 */
function choiceClientele(){
	$("#clienteleTbody").html("");
	var newRows = '';
	 $.getJSON("/jeesite/a/pro/realDetail/clienteleList",function(data){
		 if (typeof(data.list) != "undefined" && data.list.length >= 1){
			 $.each(data.list, function(i,clientele){
				newRows += "<tr><td style=\"width: 8px;\"><input type=\"radio\" class=\"subBox\" name=\"radio\"/></td><td>"+clientele.codeNum+"</td><td>"+clientele.name+"</td><td>"+clientele.phone+
				 "</td><td>"+clientele.fax+"</td><td>"+clientele.email+"</td><td style='display:none;'>"+clientele.id+
				 "</td></tr>";
			});	
		 }
		 $("#clienteleTbody").append(newRows);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#clientelePageNo").html(pageNoOne);
			$("#clientelePageSize").html(pageSizeOne);
			$("#clienteleCount").html(countOne);
		if(pageNoOne <= 1){
			$("#clientelePreviousPageLi").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#clienteleNextPageLi").attr("class","disabled");
		}
		// 弹出选择框
		ejectClienteleInfo();
	});
}

/**
 * 搜索客户
 * 
 * @param obj
 */
function selectClientele(obj){
	clienteleName = $(obj).prev().val();
	$("#clienteleTbody").html(" ");
	var  newRow = "";
	$.getJSON("/jeesite/a/pro/realDetail/clienteleList","name="+clienteleName,function(data){
		if (typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i,clientele){
				newRow += '<tr><td style="width: 8px;">'
					 +'<input type="radio"class="subBox" name="radio" value=""/></td>'
					 +'<td>'+clientele.codeNum+'</td>'
					 +'<td>'+clientele.name+'</td>'
					 +'<td>'+clientele.phone+'</td>'
					 +'<td>'+clientele.fax+'</td>'
					 +'<td>'+clientele.email+'</td>'
					 +'<td style="display:none;">'+clientele.id+'</td></tr>';
			});
			$("#clienteleTbody").append(newRow);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#clientelePageNo").html(pageNoOne);
			$("#clientelePageSize").html(pageSizeOne);
			$("#clienteleCount").html(countOne);
		}
		if(pageNoOne <= 1){
			$("#clientelePreviousPageLi").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#clienteleNextPageLi").attr("class","disabled");
		}
		$.jBox.close(jBoxClienteleInfo);
		ejectClienteleInfo();
	});
}





/**
 * 修改合同产品信息
 * 
 * @param obj
 */
function modifyRealDetail(obj){
	$("#productNameModify").attr('value',$(obj).parent().parent().children("td").children("span[class=productInfoNameSpan]").html());
	$("#productCodeModify").attr('value',$(obj).parent().parent().children("td").children("span[class=productCodeSpan]").html());
	$("#specificationsModify").attr('value',$(obj).parent().parent().children("td").children("span[class=specificationsSpan]").html());
	$("#brandModify").attr('value',$(obj).parent().parent().children("td").children("span[class=brandSpan]").html());
	$("#packagingModify").attr('value',$(obj).parent().parent().children("td").children("span[class=packagingSpan]").html());
	$("#unitModify").attr('value',$(obj).parent().parent().children("td").children("span[class=unitNameSpan]").html());
	$("#supplierModify").attr('value',$(obj).parent().parent().children("td").children("span[class=supplierNameSpan]").html());
	$("#executorModify").attr('value',$(obj).parent().parent().children("td").children("span[class=executorSpan]").html());
	$("#noTaxPriceModify").attr('value',$(obj).parent().parent().children("td").children("span[class=noTaxPriceSpan]").html());
	$("#taxPriceModify").attr('value',$(obj).parent().parent().children("td").children("span[class=taxPriceSpan]").html());
	$("#countModify").attr('value',$(obj).parent().parent().children("td").children("span[class=countSpan]").html());
	$("#marketPriceModify").attr('value',$(obj).parent().parent().children("td").children("span[class=marketPriceSpan]").html());
	$("#brandReplaceModify").attr('value',$(obj).parent().parent().children("td").children("span[class=brandReplaceSpan]").html());
	$("#abnormalProblemModify").attr('value',$(obj).parent().parent().children("td").children("span[class=abnormalProblemSpan]").html());
	$("#enquiryDateModify").attr('value',$(obj).parent().parent().children("td").children("span[class=enquiryDateSpan]").html());
	$("#deliveryAddressModify").attr('value',$(obj).parent().parent().children("td").children("span[class=deliveryAddressSpan]").html());
	$("#deliveryDateModify").attr('value',$(obj).parent().parent().children("td").children("span[class=deliveryDateSpan]").html());
	$("#paymentDateModify").attr('value',$(obj).parent().parent().children("td").children("span[class=paymentDateSpan]").html());
	$("#arriveDateModify").attr('value',$(obj).parent().parent().children("td").children("span[class=arriveDateSpan]").html());
	$("#expirationDateModify").attr('value',$(obj).parent().parent().children("td").children("span[class=expirationDateSpan]").html());
	$("#remarksModify").html($(obj).parent().parent().children("td").children("span[class=remarksSpan]").html());
	
	$("#productCodeNumModify").attr('value',$(obj).parent().parent().children("td").children("span[class=productCodeNumSpan]").html());
	$("#supplierCodeNumModify").attr('value',$(obj).parent().parent().children("td").children("span[class=supplierCodeNumSpan]").html());
	
}


/**
 * 弹出修改合同产品信息框
 * 
 * @param obj
 */
function ejectModifyRealDetail(obj){
	modifyRealDetail(obj);
	$.jBox($("#divModifyPro").html(), {
		id: 'jBoxModifyPro', 
		title : "添加产品",
		width : 555,
		height : 555,
		buttons : {"选择" : false , "关闭" : true },
		submit : function(v, h, f) {
			if (v == false) {
				$(obj).parent().parent().children("td").children("span[class=productInfoNameSpan]").html(h.find("#productNameModify").val());
				$(obj).parent().parent().children("td").children("span[class=productCodeSpan]").html(h.find("#productCodeModify").val());
				$(obj).parent().parent().children("td").children("span[class=specificationsSpan]").html(h.find("#specificationsModify").val());
				$(obj).parent().parent().children("td").children("span[class=brandSpan]").html(h.find("#brandModify").val());
				$(obj).parent().parent().children("td").children("span[class=packagingSpan]").html(h.find("#packagingModify").val());
				$(obj).parent().parent().children("td").children("span[class=unitNameSpan]").html(h.find("#unitModify").val());
				$(obj).parent().parent().children("td").children("span[class=supplierNameSpan]").html(h.find("#supplierModify").val());
				$(obj).parent().parent().children("td").children("span[class=noTaxPriceSpan]").html(h.find("#noTaxPriceModify").val());
				$(obj).parent().parent().children("td").children("span[class=taxPriceSpan]").html(h.find("#taxPriceModify").val());
				$(obj).parent().parent().children("td").children("span[class=countSpan]").html(h.find("#countModify").val());
				$(obj).parent().parent().children("td").children("span[class=marketPriceSpan]").html(h.find("#marketPriceModify").val());
				$(obj).parent().parent().children("td").children("span[class=brandReplaceSpan]").html(h.find("#brandReplaceModify").val());
				$(obj).parent().parent().children("td").children("span[class=abnormalProblemSpan]").html(h.find("#abnormalProblemModify").val());
				$(obj).parent().parent().children("td").children("span[class=enquiryDateSpan]").html(h.find("#enquiryDateModify").val());
				$(obj).parent().parent().children("td").children("span[class=deliveryAddressSpan]").html(h.find("#deliveryAddressModify").val());
				$(obj).parent().parent().children("td").children("span[class=deliveryDateSpan]").html(h.find("#deliveryDateModify").val());
				$(obj).parent().parent().children("td").children("span[class=paymentDateSpan]").html(h.find("#paymentDateModify").val());
				$(obj).parent().parent().children("td").children("span[class=arriveDateSpan]").html(h.find("#arriveDateModify").val());
				$(obj).parent().parent().children("td").children("span[class=expirationDateSpan]").html(h.find("#expirationDateModify").val());
				$(obj).parent().parent().children("td").children("span[class=remarksSpan]").html(h.find("#remarksModify").val());
				$(obj).parent().parent().children("td").children("span[class=executorSpan]").html(h.find("#executorModify").val());
				
				$(obj).parent().parent().children("td").children("span[class=productCodeNumSpan]").html(h.find("#productCodeNumModify").val());
				$(obj).parent().parent().children("td").children("span[class=supplierCodeNumSpan]").html(h.find("#supplierCodeNumModify").val());
				
				$(obj).parent().parent().children("td").children("input[name=name]").val(h.find("#productNameModify").val());
				$(obj).parent().parent().children("td").children("input[name=productCode]").val(h.find("#productCodeModify").val());
				$(obj).parent().parent().children("td").children("input[name=specifications]").val(h.find("#specificationsModify").val());
				$(obj).parent().parent().children("td").children("input[name=brand]").val(h.find("#brandModify").val());
				$(obj).parent().parent().children("td").children("input[name=packaging]").val(h.find("#packagingModify").val());
				$(obj).parent().parent().children("td").children("input[name=unit]").val(h.find("#unitModify").val());
				$(obj).parent().parent().children("td").children("input[name=supplier]").val(h.find("#supplierModify").val());
				$(obj).parent().parent().children("td").children("input[name=noTaxPrice]").val(h.find("#noTaxPriceModify").val());
				$(obj).parent().parent().children("td").children("input[name=taxPrice]").val(h.find("#taxPriceModify").val());
				$(obj).parent().parent().children("td").children("input[name=count]").val(h.find("#countModify").val());
				$(obj).parent().parent().children("td").children("input[name=marketPrice]").val(h.find("#marketPriceModify").val());
				$(obj).parent().parent().children("td").children("input[name=brandReplace]").val(h.find("#brandReplaceModify").val());
				$(obj).parent().parent().children("td").children("input[name=abnormalProblem]").val(h.find("#abnormalProblemModify").val());
				$(obj).parent().parent().children("td").children("input[name=enquiryDate]").val(h.find("#enquiryDateModify").val());
				$(obj).parent().parent().children("td").children("input[name=deliveryAddress]").val(h.find("#deliveryAddressModify").val());
				$(obj).parent().parent().children("td").children("input[name=deliveryDatea]").val(h.find("#deliveryDateModify").val());
				$(obj).parent().parent().children("td").children("input[name=paymentDate]").val(h.find("#paymentDateModify").val());
				$(obj).parent().parent().children("td").children("input[name=arriveDate]").val(h.find("#arriveDateModify").val());
				$(obj).parent().parent().children("td").children("input[name=expirationDate]").val(h.find("#expirationDateModify").val());
				$(obj).parent().parent().children("td").children("input[name=realDetailRemarks]").val(h.find("#remarksModify").val());
				$(obj).parent().parent().children("td").children("input[name=executor]").val(h.find("#executorModify").val());
				
				$(obj).parent().parent().children("td").children("input[name=productCodeNum]").val(h.find("#productCodeNumModify").val());
				$(obj).parent().parent().children("td").children("input[name=supplierCodeNum]").val(h.find("#supplierCodeNumModify").val());
				
				return true;
			}
		}
	});
}


/**
 * 删除
 */
$(".deleteRow").live("click",function(){
	var obj = $(this);
	var submit = function (v, h, f) {
		if (v == 'ok'){ 
			dIds[i] = $(obj).parent().parent().children("td:eq(0)").children("input:eq(0)").val();
			i++;
			$(obj).parent().parent().remove();
		}else if (v == 'cancel'){
			return true;
		}
	};
	$.jBox.confirm("确认删除此信息吗？", "提示", submit); 
}); 

/**
 * 客户下一页
 */
$("#clienteleNextPage").live("click",function(){
	if(pageNoOne < countOne/pageSizeOne){
		$("#clienteleTbody").html("");
		$.getJSON("/jeesite/a/pro/realDetail/clienteleList","pageNo="+(pageNoOne+1)+"&name="+clienteleName,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i,clientele){
					 var newRow=  "<tr><td style=\"width: 8px;\"><input type=\"radio\" class=\"subBox\" name=\"radio\"/></td><td>"+clientele.codeNum+"</td><td>"+clientele.name+"</td><td>"+clientele.phone+
					 "</td><td>"+clientele.fax+"</td><td>"+clientele.email+"</td><td style='display:none;'>"+clientele.id+
					 "</td></tr>";
					$("#clienteleTbody").append(newRow);
				});
				pageNoOne = data.pageNo;
				pageSizeOne = data.pageSize;
				countOne = data.count;
				$("#clientelePageNo").html(pageNoOne);
				$("#clientelePageSize").html(pageSizeOne);
				$("#clienteleCount").html(countOne);
				$("#clientelePreviousPageLi").attr("class","");
			}
			if(pageNoOne <= 1){
				$("#clientelePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#clienteleNextPageLi").attr("class","disabled");
			}
			$.jBox.close(jBoxClienteleInfo);
			ejectClienteleInfo();
		});
	}
});

/**
 * 客户上一页
 */
$("#clientelePreviousPage").live("click",function(){
	if(pageNoOne > 1){
		$("#clienteleTbody").html("");
		$.getJSON("/jeesite/a/pro/realDetail/clienteleList","pageNo="+(pageNoOne-1)+"&name="+clienteleName,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i,clientele){
					var newRow=  "<tr><td style=\"width: 8px;\"><input type=\"radio\" class=\"subBox\" name=\"radio\"/></td><td>"+clientele.codeNum+"</td><td>"+clientele.name+"</td><td>"+clientele.phone+
						 "</td><td>"+clientele.fax+"</td><td>"+clientele.email+"</td><td style='display:none;'>"+clientele.id+
						 "</td></tr>";	
					$("#clienteleTbody").append(newRow);
				});
				pageNoOne = data.pageNo;
				pageSizeOne = data.pageSize;
				countOne = data.count;
				$("#clientelePageNo").html(pageNoOne);
				$("#clientelePageSize").html(pageSizeOne);
				$("#clienteleCount").html(countOne);
				$("#clienteleNextPageLi").attr("class","");
			}
			if(pageNoOne <= 1){
				$("#clientelePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#clienteleNextPageLi").attr("class","disabled");
			}
			$.jBox.close(jBoxClienteleInfo);
			ejectClienteleInfo();
		});
	}
});

/**
 * 导入导出
 */
$("#btnExport").live("click",function() {
	var realContractId = $("#realContractId").val();// 客户合同ID
	top.$.jBox.confirm("确认要导出产品数据吗？", "系统提示", function(v, h, f) {
		if (v == "ok") {
			window.location.href="/jeesite/a/pro/realDetail/export?ID="+realContractId;
		}
	}, {
		buttonsFocus : 1
	});
		top.$('.jbox-body .jbox-icon').css('top', '55px');
	});
$("#btnImport").live("click",function() {
	$.jBox($("#importBox").html(), {
		title : "导入数据",
		buttons : {
			"关闭" : true
		},
		bottomText : "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
	});
});

